//
// Created by Semir on 2020/4/25.
//

#include <iostream>

using namespace std;

const int MAX_R = 1001;
int r;
int dp[MAX_R][MAX_R];

int main() {
    cin >> r;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j <= i; j++) {
            cin >> dp[i][j];
        }
    }
    for (int i = r - 2; i >= 0; i--) {
        for (int j = 0; j <= i; j++) {
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j + 1]) + dp[i][j];
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}